package com.idheima.zuoye.zuoye6;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) {
        ArrayList<Global> list = new ArrayList<>();
        list.add(new Global("肖生克的救赎", 9.7));
        list.add(new Global("霸王别姬", 9.6));
        list.add(new Global("阿甘正传", 9.6));
        list.add(new Global("辛德勒的名单", 9.6));
        list.add(new Global("东游记", 9.5));
        list.add(new Global("千与千寻", 9.5));
        list.add(new Global("唐顿庄园", 9.5));
        list.add(new Global("这个杀手不太冷", 9.4));

        ArrayList<Huaren> list1 = new ArrayList<>();
        list1.add(new Huaren("阳光普照", 9.7));
        list1.add(new Huaren("气球", 9.6));
        list1.add(new Huaren("拆弹专家2", 9.6));
        list1.add(new Huaren("一秒钟", 9.6));
        list1.add(new Huaren("送你一朵小红花", 9.5));
        list1.add(new Huaren("金都", 9.5));
        list1.add(new Huaren("叔叔", 9.5));
        list1.add(new Huaren("小森林", 9.4));

        Map<String, Double> map = new HashMap<>();
        for (int i = 0; i < list.size(); i++) {
            map.put(list.get(i).getName(), list.get(i).getScore());
        }
        map.entrySet().stream()
                .sorted(((o1, o2) -> o2.getValue().compareTo(o1.getValue())))
                .forEach(entry -> System.out.println(entry.getKey() + "---" + entry.getValue()));

        System.out.println("===========================");
        Map<String, Double> map1 = new HashMap<>();
        for (int i = 0; i < list1.size(); i++) {
            map1.put(list1.get(i).getName(), list1.get(i).getScore());
        }
        map1.entrySet().stream()
                .sorted(((o1, o2) -> o2.getValue().compareTo(o1.getValue())))
                .forEach(entry -> System.out.println(entry.getKey() + "---" + entry.getValue()));

        System.out.println("===========================");
        map.entrySet()
                .stream()
                //取前几个
                .sorted(((o1, o2) -> o2.getValue().compareTo(o1.getValue())))
                .limit(3)
                .forEach(entry -> System.out.println(entry.getKey() + "---" + entry.getValue()));
        System.out.println("===========================");
        map1.entrySet()
                .stream()
                .sorted(((o1, o2) -> o2.getValue().compareTo(o1.getValue())))
                //取倒数几个
                .skip(map1.size() - 5)
                .forEach(entry -> System.out.println(entry.getKey() + "---" + entry.getValue()));
        System.out.println("===========================");
        Stream<Map.Entry<String, Double>> limit = map.entrySet()
                .stream()
                .sorted(((o1, o2) -> o2.getValue().compareTo(o1.getValue())))
                .limit(5);
        Stream<Map.Entry<String, Double>> limit1 = map1.entrySet()
                .stream()
                .sorted(((o1, o2) -> o2.getValue().compareTo(o1.getValue())))
                .limit(5);
        Stream.concat(limit, limit1).map(e->new Film(e.getKey(),e.getValue())).
        forEach(film -> System.out.println(film.getName() + "---" + film.getScore()));



    }


}
